/*
 * Copyright 2006-2022 ahtelit.com, All Rights Reserved.
 */

package com.telit.dispose.feign.factory;

import com.telit.common.entity.DataReturn;
import com.telit.common.entity.PageData;
import com.telit.common.enums.ResultCode;
import com.telit.common.util.LanguageUtils;
import com.telit.dispose.dto.PlatMetaTableEntityDTO;
import com.telit.dispose.entity.dispose.PlatMetaFieldEntity;
import com.telit.dispose.entity.resourceManagement.Dict;
import com.telit.dispose.feign.RemoteDisposeService;
import com.telit.dispose.model.QryDeviceListRequest;
import com.telit.dispose.model.QryDeviceModel;
import com.telit.dispose.model.QryResourceListRequest;
import com.telit.dispose.model.QryResourceModel;
import com.telit.dispose.vo.resourceManagement.DictVO;
import com.telit.dispose.vo.resourceManagement.ResourceCategoryVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * RemoteDisposeServiceFallbackFactory
 *
 * @author yuezhuang
 * @since 2022-12-14
 */
@Slf4j
@Component
public class RemoteDisposeServiceFallbackFactory implements FallbackFactory<RemoteDisposeService> {

    @Override
    public RemoteDisposeService create(Throwable cause) {
        return new RemoteDisposeService() {

            /**
             * 标准化输出微服务内部调用错误信息
             *
             * @return DataReturn
             */
            private DataReturn defaultFallback() {
                String msg = LanguageUtils.codeMessage(ResultCode.SERVER_FEIGN_ERROR.getCode(), cause.getMessage());
                log.error(msg, cause);
                return DataReturn.failure(ResultCode.SERVER_FEIGN_ERROR.getCode(), msg);
            }

            @Override
            public DataReturn selectAllTable(String flag) {
                return defaultFallback();
            }

            @Override
            public DataReturn selectTableInfoByTableName(String tables, String districtCode) {
                return defaultFallback();
            }

            @Override
            public DataReturn findDictInfoByCode(String parentCode, String childCode) {
                return defaultFallback();
            }

            @Override
            public DataReturn<List<DictVO>> findDictByDictType(String code) {
                return defaultFallback();
            }

            @Override
            public DataReturn<List<ResourceCategoryVO>> topFloorDownChildrenList(Long parentId, String longitude, String latitude, String radius, String districtCode) {
                return defaultFallback();
            }

            @Override
            public DataReturn dictInsert(Dict dict) {
                return defaultFallback();
            }

            @Override
            public DataReturn deleteDictById(Long id) {
                return defaultFallback();
            }

            @Override
            public DataReturn<Dict> selectByDictId(Long id) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PageData<List<QryResourceModel>>> qryResourceList(
                    QryResourceListRequest qryResourceListRequest) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PageData<List<QryDeviceModel>>> qryDeviceList(QryDeviceListRequest qryDeviceListRequest) {
                return defaultFallback();
            }

            @Override
            public DataReturn<QryDeviceModel> qryDeviceDetail(String tableId, String id) {
                return defaultFallback();
            }

            @Override
            public DataReturn<QryResourceModel> qryResourceDetail(String tableId, String id) {
                return defaultFallback();
            }

            @Override
            public DataReturn<List<PlatMetaFieldEntity>> selectTableAndFilesByTableId(String tableId) {
                return defaultFallback();
            }

            @Override
            public DataReturn dateSelectByService(String tableId, String service, Integer current, Integer size,
                                                  String name, String data, String detailId, String xzqhcode) {
                return defaultFallback();
            }

            @Override
            public DataReturn<PlatMetaTableEntityDTO> selectTableByTableId(String tableId) {
                return defaultFallback();
            }
        };
    }

}
